<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1{
            width: 300px;height: 300px;background: red;margin: 0 auto;
        }
        .box2{
            width: 200px;height: 200px;background: green;margin: auto;
        }
        .box3{
            width: 100px;height: 100px;background: blue;margin: auto;padding-top: 40px;
            box-sizing: border-box;
        }
        span{
            width: 300px;height: 300px;background: pink;margin: auto;
        }
    </style>
</head>
<body>
    <div class="box1">
        <div class="box2">
            <div class="box3">
                <span>张新同小帅逼</span>
            </div>
        </div>
    </div>
</body>
<script>
    // 获取元素
    var obox1=document.querySelector(".box1");
    var obox2=document.querySelector(".box2");
    var obox3=document.querySelector(".box3");
    var ospan=document.querySelector("span");
    
    // 绑定事件
    obox1.onclick=function(){
        console.log("red");
    }
    obox2.onclick=function(){
        console.log("green");
    }
    obox3.onclick=function(){
        console.log("blue");
    }
    ospan.onclick=function(){
        console.log("pink");
    }
</script>
</html>